﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using ServiceApplication.Service.Plan;
using OAclient.Models;
using CommonLibrary.Common;
using CommonLibrary.DataModel.Plan;
using OAclient.Filters;

namespace OAclient.Controllers
{
    [VaildateLogin]
    [ExceptionFilter]
    [LoggerFilter]
    public class GroupController : Controller
    {
        //
        // GET: /Group/
        PlanService ps = new PlanService();

        public ActionResult GroupTree()
        {
            return PartialView();
        }

        public ActionResult GroupList(UserModel user)
        {
            var dt = ps.QueryGroupByCreaterId(user.user.user_id);
            ViewData["dt"] = dt;
            return PartialView();
        }

        public ActionResult GroupAdd(UserModel user)
        {
            ViewData["creater_id"] = user.user.user_id;
            return PartialView();
        }

        #region 方法


        public string DoGroupAdd(int creater_id, string groupname, string groupmembers)
        {
            if (null != ps.QueryGroup(creater_id, groupname))
            {
                return "已存在该组名!";
            }

            GroupEntity groupEntity = new GroupEntity()
            {
                creater_id = 1,
                group_name = groupname,
                group_users = groupmembers,
                group_createtime = DateTime.Now.ToString(),
                group_descn = ""
            };
            ps.AddGroup(groupEntity);
            ViewData["grouptree"] = Node.ConvertToZtree(ps.QueryGroupTreeByCreaterId(creater_id));//更新viewdata数据树
            return "操作成功！";
        }

        public string DoGroupDelete()
        {
            return "";
        }
        #endregion

    }
}
